package org.example;

import java.util.Iterator;

/**
 * @author hangwen
 * @date 2023/11/7
 */
public class LinkListMain {
    public static void main(String[] args) {
        LinkList linkList = new LinkList();

        linkList.addLast(1);
        linkList.addLast(2);
        linkList.addLast(3);
        linkList.addFirst(0);
        linkList.addIndex(2, 10);


        //1.foreach
        System.out.println("---foreach 迭代---");
        for (Object o : linkList) {
            System.out.println(o);
        }
        System.out.println("---end---");

        //2.forward
        System.out.println("---forward 迭代---");
        linkList.forward(System.out::println);
        System.out.println("---end---");

        //3.forward
        System.out.println("---backward 迭代---");
        linkList.backward();

        //4.获取forward跌代器
        Iterator<Object> itr = linkList.getForwardItr();
        while (itr.hasNext()) {
            final Object o = itr.next();
            System.out.println(o);
        }

        //5.获取forward跌代器
        itr = linkList.getBackItr();
        while (itr.hasNext()) {
            final Object o = itr.next();
            System.out.println(o);
        }


        linkList.remove(2);
        linkList.backward();

        System.out.println(linkList.size());
        linkList.clear();
        System.out.println(linkList.size());


    }
}
